using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace CommandPatternApp
{
    public class PasteCmd : UndoableCmd
    {
        private string _selText;
        private int _selStart;
        private int _pasteLen;

        public PasteCmd(TextEditor editor, CmdFactory factory)
            : base(editor, factory)
        {
            _selStart = editor.SelectionStart;
            _selText = editor.SelectedText;
            _pasteLen = Clipboard.GetText().Length;
        }

        public override string Name
        {
            get { return "Paste"; }
        }

        public override void Execute()
        {
            PasteCmd cmd = _factory.PasteCmd();  
            _editor.Paste(cmd);
        }

        public override void Undo()
        {
            _editor.UndoPaste(_selStart, _selText, _pasteLen);
        }

    }
}
